// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Dispatcher.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the Dispatcher type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Threading
{
    using System;

    public class Dispatcher : IDispatcher
    {
        #region Fields

        private static IDispatcher _default;
        private static IDispatcher _threadPool;

        #endregion

        public static IDispatcher Synchronous
        {
            get { return _default ?? (_default = new Dispatcher()); }
        }

        public static IDispatcher ThreadPool
        {
            get
            {
                if (_threadPool == null)
                {
                    _threadPool = new ThreadPoolDispatcher();
                }
                return _threadPool;
            }
        }

        public static IDispatcher FromCurrentSynchronizationContext()
        {
            return new SynchronizationContextDispatcher();
        }

        public static IDispatcher FromCurrentUIContext()
        {
            return UIDispatcher.Current;
        }

        public void BeginInvoke(Action action)
        {
            action();
        }

        public bool CheckAccess()
        {
            return false;
        }
    }
}